@yltrcc/vditor 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.css +2 -2
- package/dist/index.js +51 -5
- package/dist/index.min.js +1 -1
- package/dist/method.js +3 -3
- package/dist/method.min.js +1 -1
- package/package.json +1 -1
- package/src/ts/markdown/getMarkdown.ts +60 -12
package/dist/index.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.6 - A markdown editor written in TypeScript.
|
|
3
3
|
*
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*
|
|
26
26
|
*/
|
|
27
27
|
/*!
|
|
28
|
-
* Vditor v0.0.
|
|
28
|
+
* Vditor v0.0.6 - A markdown editor written in TypeScript.
|
|
29
29
|
*
|
|
30
30
|
* MIT License
|
|
31
31
|
*
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Vditor v0.0.
|
|
2
|
+
* Vditor v0.0.6 - A markdown editor written in TypeScript.
|
|
3
3
|
*
|
|
4
4
|
* MIT License
|
|
5
5
|
*
|
|
@@ -1267,7 +1267,7 @@ var looseJsonParse = function (text) {
|
|
|
1267
1267
|
/* harmony export */ Y: () => (/* binding */ Constants),
|
|
1268
1268
|
/* harmony export */ g: () => (/* binding */ _VDITOR_VERSION)
|
|
1269
1269
|
/* harmony export */ });
|
|
1270
|
-
var _VDITOR_VERSION = "0.0.
|
|
1270
|
+
var _VDITOR_VERSION = "0.0.6";
|
|
1271
1271
|
|
|
1272
1272
|
var Constants = /** @class */ (function () {
|
|
1273
1273
|
function Constants() {
|
|
@@ -1315,7 +1315,7 @@ var Constants = /** @class */ (function () {
|
|
|
1315
1315
|
// 别名
|
|
1316
1316
|
"js", "ts", "html", "toml", "c#", "bat"
|
|
1317
1317
|
];
|
|
1318
|
-
Constants.CDN = "https://unpkg.com/@yltrcc/vditor@".concat("0.0.
|
|
1318
|
+
Constants.CDN = "https://unpkg.com/@yltrcc/vditor@".concat("0.0.6");
|
|
1319
1319
|
Constants.MARKDOWN_OPTIONS = {
|
|
1320
1320
|
autoSpace: false,
|
|
1321
1321
|
gfmAutoLink: true,
|
|
@@ -5066,15 +5066,61 @@ var constants = __webpack_require__(357);
|
|
|
5066
5066
|
var code160to32 = __webpack_require__(435);
|
|
5067
5067
|
;// ./src/ts/markdown/getMarkdown.ts
|
|
5068
5068
|
|
|
5069
|
+
/**
|
|
5070
|
+
* 将 doclink DOM 元素转换回 Markdown 语法
|
|
5071
|
+
* 处理 <span class="vditor-doclink-wrapper" data-doc-markdown="((id 'text'))">text</span>
|
|
5072
|
+
*/
|
|
5073
|
+
var processDocLinksInHTML = function (html) {
|
|
5074
|
+
// 创建临时 DOM 元素来解析 HTML
|
|
5075
|
+
var tempDiv = document.createElement("div");
|
|
5076
|
+
tempDiv.innerHTML = html;
|
|
5077
|
+
// 查找所有 doclink wrapper 元素
|
|
5078
|
+
var docLinkWrappers = tempDiv.querySelectorAll(".vditor-doclink-wrapper");
|
|
5079
|
+
docLinkWrappers.forEach(function (wrapper) {
|
|
5080
|
+
var markdown = wrapper.getAttribute("data-doc-markdown");
|
|
5081
|
+
if (markdown) {
|
|
5082
|
+
// 用文本节点替换整个 wrapper,内容为 Markdown 语法
|
|
5083
|
+
wrapper.replaceWith(document.createTextNode(markdown));
|
|
5084
|
+
}
|
|
5085
|
+
else {
|
|
5086
|
+
// 如果没有 data-doc-markdown,尝试从 data-doc-id 和 data-doc-text 重建
|
|
5087
|
+
var id = wrapper.getAttribute("data-doc-id");
|
|
5088
|
+
var text = wrapper.getAttribute("data-doc-text");
|
|
5089
|
+
if (id && text) {
|
|
5090
|
+
wrapper.replaceWith(document.createTextNode("((".concat(id, " '").concat(text, "'))")));
|
|
5091
|
+
}
|
|
5092
|
+
}
|
|
5093
|
+
});
|
|
5094
|
+
// 也处理旧的 .vditor-doclink 元素(没有 wrapper 的情况)
|
|
5095
|
+
var docLinks = tempDiv.querySelectorAll(".vditor-doclink");
|
|
5096
|
+
docLinks.forEach(function (link) {
|
|
5097
|
+
var markdown = link.getAttribute("data-doc-markdown");
|
|
5098
|
+
if (markdown) {
|
|
5099
|
+
link.replaceWith(document.createTextNode(markdown));
|
|
5100
|
+
}
|
|
5101
|
+
else {
|
|
5102
|
+
var id = link.getAttribute("data-doc-id");
|
|
5103
|
+
var text = link.getAttribute("data-doc-text");
|
|
5104
|
+
if (id && text) {
|
|
5105
|
+
link.replaceWith(document.createTextNode("((".concat(id, " '").concat(text, "'))")));
|
|
5106
|
+
}
|
|
5107
|
+
}
|
|
5108
|
+
});
|
|
5109
|
+
return tempDiv.innerHTML;
|
|
5110
|
+
};
|
|
5069
5111
|
var getMarkdown = function (vditor) {
|
|
5070
5112
|
if (vditor.currentMode === "sv") {
|
|
5071
5113
|
return (0,code160to32/* code160to32 */.p)("".concat(vditor.sv.element.textContent, "\n").replace(/\n\n$/, "\n"));
|
|
5072
5114
|
}
|
|
5073
5115
|
else if (vditor.currentMode === "wysiwyg") {
|
|
5074
|
-
|
|
5116
|
+
// 先处理 doclink 元素,将其转换回 Markdown 语法
|
|
5117
|
+
var processedHTML = processDocLinksInHTML(vditor.wysiwyg.element.innerHTML);
|
|
5118
|
+
return vditor.lute.VditorDOM2Md(processedHTML);
|
|
5075
5119
|
}
|
|
5076
5120
|
else if (vditor.currentMode === "ir") {
|
|
5077
|
-
|
|
5121
|
+
// 同样处理 IR 模式
|
|
5122
|
+
var processedHTML = processDocLinksInHTML(vditor.ir.element.innerHTML);
|
|
5123
|
+
return vditor.lute.VditorIRDOM2Md(processedHTML);
|
|
5078
5124
|
}
|
|
5079
5125
|
return "";
|
|
5080
5126
|
};
|